<?php

// crime.js.php
// Michael Baker
// 2010.07
//
// output javascript for workflow creation page

$q = ui_get_node_options();
$q2 = str_replace( "\n", "", $q );

?>
<!-- I realize how horrible this javascript code is. I'm earnestly sorry. -MB -->
<script type="text/javascript">

function addElement() {
	var ni = document.getElementById('nodelist');
	var numi = document.getElementById('argc');
	var num = (numi.value - 1) + 2;
	numi.value = num;

	var newdl = document.createElement('dl');
	var dlIdName = 'nodeline' + num;
	newdl.setAttribute( 'id', dlIdName );
	newdl.innerHTML = "<dt><label for=\"n" + num + "\">Node " + num + "</label></dt><dd><select name=\"n" + num + "\" id=\"n" + num + "\">" + <?php echo '"' . addslashes($q2) . '"'; ?> + "</select></dd>";
	ni.appendChild( newdl );
	return dlIdName;
}

function addElement2() {
	var ni = document.getElementById('nodelist');
	var numi = document.getElementById('argc');
	var num = (numi.value - 1) + 2;
	numi.value = num;
	
	var newdl = document.createElement('dl');
	var dlIdName = 'nodeline' + num;
	newdl.setAttribute( 'id', dlIdName );
	newdl.innerHTML = "<dt><label for=\"n" + num + "\">Node " + num + "</label></dt><dd><input name=\"n" + num + "\" id=\"n" + num + "\" /></dd>";
	ni.appendChild( newdl );
	return dlIdName;
}

function dropElement() {
	var numi = document.getElementById('argc');
	var num = (numi.value);
	
	var old = document.getElementById('nodeline' + num);
	if (!old) { return; }
	var ni = document.getElementById('nodelist');
	
	numi.value = num - 1;
	
	ni.removeChild( old );
	
}

</script>